package com.edu.controller;

import com.edu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadController {


    @RequestMapping("/upload1")
    public String upload1(MultipartFile mf) throws IOException {
        System.out.println(mf);
        System.out.println(mf.getName());//获取文件域中name属性的值
        System.out.println(mf.getOriginalFilename());//获取上传文件的原始文件名
        System.out.println(mf.getContentType());//获取上传文件的类型
        System.out.println(mf.getSize());//获取上传文件的大小
        File dest = new File("c://headImgs/"+mf.getOriginalFilename());
        mf.transferTo(dest);
        return "/index.jsp";
    }

    @RequestMapping("/upload2")
    public String upload1(MultipartFile mf, User user) throws IOException {
        System.out.println(user);
        mf.transferTo(new File("c://headImgs/"+mf.getOriginalFilename()));
        return "/index.jsp";
    }

}
